package com.wlstock.funi.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.view.View;

import com.em.adapter.CommonAdapter;
import com.em.adapter.ViewHolder;
import com.wlstock.funi.R;
import com.wlstock.funi.model.OperateModel;
import com.wlstock.funi.model.TradeHisModel;
import com.wlstock.funi.utils.StockUtils;

public class TradeHisAdapter extends CommonAdapter<TradeHisModel> {

	private SimpleDateFormat sdf;

	public TradeHisAdapter(Context context, List<TradeHisModel> datas, int layoutId) {
		super(context, datas, layoutId);
		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	}
	
	@Override
	public void convert(ViewHolder holder, TradeHisModel model) {
		
		holder.setText(R.id.tv_stk_info, model.getStkName()+"("+model.getStockNo()+")");
		holder.setText(R.id.tv_trade_type, StockUtils.parseTradeType(model.getTradeType()));
		holder.setText(R.id.tv_price_info, model.getCostPrice());
		holder.setText(R.id.tv_trade_date, sdf.format(model.getCreateDate()));
		if (model.getTradeType() == OperateModel.TradeType_BUY) {
			holder.getView(R.id.tv_profit).setVisibility(View.GONE);
		}else if (model.getTradeType() == OperateModel.TradeType_SELL) {
			holder.getView(R.id.tv_profit).setVisibility(View.VISIBLE);
			holder.setText(R.id.tv_profit, model.getProfitRate()+"%");
		}
		
		
	}

}
